package com.tenglong.teacher.ui.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Pattern;

public class MyUtils {
    final public static  String TAG = "cuotibao";
    final public static  String CLASSID = "classid";
    final public static  String CLASSIDLIST = "classid_list";
    final public static  String CLASSNAME = "classname";
    final public static  String CLASSDateTimeFrom= "CLASSDateTimeFrom";
    final public static  String CLASSDateTimeTo= "CLASSDateTimeTo";
    final public static  String CLASSPROTEACHER = "teacherproName";
    final public static  String CLASSCOURSENAME = "courseName";
    final public static  String CLASSHOUR = "classhour";
    final public static  String CLASSSTUNUM = "stucount";

    static public boolean isUrl(String url){
        String regex = "^([hH][tT]{2}[pP]:/*|[hH][tT]{2}[pP][sS]:/*|[fF][tT][pP]:/*)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~\\/])+(\\?{0,1}(([A-Za-z0-9-~]+\\={0,1})([A-Za-z0-9-~]*)\\&{0,1})*)$";
        Pattern pattern = Pattern.compile(regex);
        return  (pattern.matcher(url).matches());
    }
    public static String dateToString(long time) {
        SimpleDateFormat formatter;
        formatter = new SimpleDateFormat("MM月dd日 HH:mm");
        if (time != 0) {
            return formatter.format(new Date(time));
        }else{
            return formatter.format(new Date());
        }
    }
    public static String dateToWeek(String datetime) {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
        Calendar cal = Calendar.getInstance(); // 获得一个日历
        Date datet = null;
        try {
            datet = f.parse(datetime);
            cal.setTime(datet);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
        if (w < 0)
            w = 0;
        return weekDays[w];
    }


    public static String getDateTimeByFormat(Date datetime,String format){
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(datetime);
    }

    /**
     * homeworkd status : Create
     */
    public static final int HW_STATUS_ALL = -1;
    public static final int HW_STATUS_SUBMIT = 0;//已提交 没批改
    public static final int HW_STATUS_CORRECT = 1;//已提交 已修改 没结束
    public static final int HW_STATUS_FINISH = 3;// 作业已经结束
    public static final int HW_STATUS_CREATE = 4;//作业老师已发布 学生没提交
    public static final String HW_STATE_CURRENT = "current";
    public static final String HW_STATE_HISTORY = "history";
}
